package cn.kgc.springmvc.controller;

import cn.kgc.springmvc.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: mosin
 * @version: v1.0  2022/5/4
 */
@Controller
@RequestMapping("/json")
public class JsonController {


    @RequestMapping("/js1")
    public String test01(){
        return  "index";
    }


    @RequestMapping("/js2")
    @ResponseBody  // 返回json类型的数据
    public User test02(){
        User user = User.builder().username("tom").password("123456").build();
        return user;
    }

    /**
     * @RequestBody   接收的参数类型是json格式
     * @param user
     * @return
     */
    @RequestMapping("/js3")
    @ResponseBody
    public User test03(@RequestBody  User user){
        System.out.println("user = " + user);
        return user;
    }
}
